package linz

interface IUSB {
    var version:String // usb 版本相关信息
    var device: String // 支持设备相关信息

    fun insert():String
}


/**
 * KT接口
 * 1. 接口本身和所有成员默认是public open
 * 2. 接口没有构造
 * 3. 接口必须重新成员变量
 */
class Mouse(override var version: String, override var device: String):IUSB {
    override fun insert(): String {
      return "Mouse $version dev: $device"
    }
}

/**
 * 实现接口的第二种方法
 */
class KeyBoard: IUSB {
    override var version: String = "USE 3.1"
        get() = field
        set(value) {
            field = value
        }
    override var device: String = "KeyBoard"
        get() {
            println("获取设备信息 field[${field}]值出去了")
            return field
        }
        set(value) {
            field = value
            println("设置设备信息 了[${value} 进来了]")
        }

    override fun insert(): String = "KeyBoard $version ， $device"

}


interface IUSB2 {
    val version:String
    get() = (1..100).shuffled().last().toString()

    val dev:String
    get() = "device info"

    fun insertUSB():String
}

class KeyBoard2 :IUSB2{
    override fun insertUSB(): String {
        return "info version:$version device$dev"
    }
}



fun main() {
    val usb:IUSB = Mouse("v1.2","Mouse")
    println(usb.insert())
    println()
    val keyBoard: IUSB = KeyBoard()

    println(keyBoard.insert())

    //todo 接口默认实现
    println("-----------------------")
    println(KeyBoard2().insertUSB())


}